<template>
  <div>
    <TopFilter ref="topFilter" :list="partInfoFilterList" :cols="4" :rows="3" :labelWidth="70" :collapse="false" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="dynamis_stock"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="true"
      selectionType="single"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="handleTableRowSelect"
      :isExportExcel="true"
      :onCalcExportData="exportFun"
      :onEnterEvent="handlePartEnterEvent"
      exportFileName="配件库存动态查询.xlsx"
      height="470"
      :onSyncTableData="handleTableDataChange"
    >
      <template slot="controls">
        <el-button type="primary" :loading="printBtnLoading" :disabled="printBtnLoading" @click="handlePrint">打印配件动态盘点清单</el-button>
      </template>
    </FilterTable>
    <!-- 月份统计类型选择 -->
    <el-radio-group v-model="yearFilterType" style="margin: 10px 0;">
      <el-radio label="2">上年同期比</el-radio>
      <el-radio label="1">本年各期比</el-radio>
    </el-radio-group>
    <!-- 月份统计 -->
    <div class="bottomInfoWrap">
      <div style="padding-right: 4px">
        <FilterTable
          ref="bottomTable"
          height="auto"
          :fetchapi="bottomApi"
          :params="bottomFetchParams"
          :isSelectColumn="false"
          :isToperInfo="false"
          :isColumnFilter="false"
          :columns="bottomColumns"
          :isPagination="false"
          :onColumnsChange="columns => (this.bottomColumns = columns)"
        ></FilterTable>
      </div>
      <div style="padding-left: 4px">
        <FilterTable
          ref="bottomTable2"
          height="auto"
          :fetchapi="bottomApi2"
          :datakey="'rows'"
          :params="bottomFetchParams2"
          :isSelectColumn="false"
          :isToperInfo="false"
          :isColumnFilter="false"
          :columns="bottomColumns2"
          :isPagination="false"
          :onColumnsChange="columns => (this.bottomColumns2 = columns)"
        ></FilterTable>
      </div>
    </div>

    <!-- 查看详情弹窗 -->
    <BaseDialog title="查看详情" :visible.sync="detailVisible" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detail :row="checkDetailRowInfo" :userList="userList" @close="detailVisible = false"></detail>
    </BaseDialog>

    <!-- 替换件查看弹窗 -->
    <BaseDialog :visible.sync="replacePartVisible" title="查看替换件" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <replaceAndInventory :partInfo="visibleReplacePartInfo"></replaceAndInventory>
    </BaseDialog>

    <!-- 打印动态盘点清单 -->
    <BasePrint ref="print" :title="入库单" :data="printData" template="part/report/templatePartInventoryInfo" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getStroageList } from '@/api/part/partOutbound/partBreak';
import { queryPartStockDetailReport, queryPartStockPartData, queryPartInventoryPrintData } from '@/api/part/report/partreport';
import { getAllUser, queryTex } from '@/api/part/common';
import detail from './detail';
import moment from 'moment';
import { queryPartMonthReport } from '@/api/part/partPurchase/purchaseOrder';
import replaceAndInventory from '@/pages/part/report/replaceAndInventory';
import { dealerPrintApi } from '@/api/repair/index.js';

export default {
  name: 'partInfo',
  components: {
    detail,
    replaceAndInventory
  },
  mixins: [dictionary],
  data() {
    return {
      partInfoFilterList: this.createPartInfoFilterList(),
      columns: this.createPartColumns(),
      fetchParams: { xhrAbort: true },
      fetchApi: queryPartStockDetailReport,
      onChangeColumn: [],
      detailVisible: false,
      checkDetailRowInfo: {}, // 查看详情的行项数据
      userList: [], // 人员列表
      tax: 0, //  税率
      yearFilterType: '1', // 下方月份统计筛选条件
      bottomFetchParams: { xhrAbort: true }, // 月份统计查询参数
      bottomApi: queryPartMonthReport,
      bottomColumns: this.createBottomColumns(),
      bottomFetchParams2: { xhrAbort: true },
      bottomApi2: queryPartStockPartData,
      bottomColumns2: this.createBottomColumns2(),
      queryInfoPart: {}, // 行数据
      replacePartVisible: false, // 是否显示替换件弹窗
      visibleReplacePartInfo: {},
      printBtnLoading: false, // 打印按钮加载状态
      printData: {}, // 打印数据
      printParams: {} // 打印参数
    };
  },
  computed: {
    ptype() {
      return this.$route.meta.ptype;
    } // 模块区分
  },
  watch: {
    yearFilterType(newVal, oldVal) {
      if (this.queryInfoPart.PART_NO) {
        this.handlePartEnterEvent();
      }
    }
  },
  mounted() {
    this.initSelect();
    this.getAllUserList();
    this.getTax();
    this.queryPrintParams(); // 获取打印参数
  },
  methods: {
    // 导出方法
    exportFun(row) {
      if (row.REFER_PRICE) {
        row.REFER_PRICE = Number(row.REFER_PRICE * (1 + Number(this.tax))).toFixed(2);
      }
      for (const key in row) {
        switch (key) {
          case 'LAST_STOCK_IN':
          case 'LAST_STOCK_OUT':
          case 'FOUND_DATE':
          case 'STOCK_AGE_DATE':
            if (row[key]) {
              row[key] = moment(row[key]).format('YYYY-MM-DD');
            }
            break;
          case 'CONSULTANT':
            if (row[key]) {
              // row[key] = this.userList[row[key]];
            }
            break;
          case 'STOCK_QUANTITY':
          case 'USERBLE_QUANTITY':
          case 'OWE_NUMBER':
          case 'LOCKED_QUANTITY':
          case 'COST_SALES_PRICE':
          case 'COST_WHOLESALES_PRICE':
          case 'LIMIT_PRICE':
          case 'URGENT_PRICE':
          case 'COST_PRICE':
          case 'NET_PRICE':
          case 'COST_AMOUNT':
          case 'NET_AMOUNT':
          case 'BORROW_QUANTITY':
          case 'LEND_QUANTITY':
            if (row[key]) {
              row[key] = Number(row[key]).toFixed(2);
            }
            break;
          default:
            break;
        }
      }
    },
    // 获取数据
    async getTax() {
      let res = await queryTex();
      this.tax = res.data;
    },
    // 获取所有员工
    async getAllUserList() {
      let res = await getAllUser();
      if (res.resultCode == 200) {
        res.data.map(e => {
          this.userList[e.userId + ''] = e.employeeName;
        });
        // console.log(this.userList, '213123');
      } else {
        this.$notify.error({ title: '提示信息', message: '获取人员列表失败' });
      }
    },
    async initSelect() {
      const res = await getStroageList();
      this.partInfoFilterList.find(x => x.fieldName === 'storageCode').itemList = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE + '' }));
      this.columns.find(x => x.dataIndex === 'STORAGE_CODE').editItems = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE + '' }));
    },
    createPartInfoFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'storageCode',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '库位代码',
          fieldName: 'storagePositionCode'
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo'
        },
        {
          type: 'INPUT',
          label: '配件说明',
          fieldName: 'partName'
        },
        {
          type: 'INPUT',
          label: '拼音代码',
          fieldName: 'spellCode'
        },
        {
          type: 'SELECT',
          label: '是否停用',
          fieldName: 'isStop',
          itemList: this.createDictList('1004')
        },
        {
          type: 'RANGE_INPUT_NUMBER',
          label: '库龄范围',
          min: 0,
          // max: 20000,
          isControls: false,
          fieldName: 'ageBegin|ageEnd'
        },
        {
          type: 'SELECT',
          label: '可用库存',
          fieldName: 'condition',
          itemList: [
            { text: '大于0', value: 1 },
            { text: '小于0', value: 2 },
            { text: '等于0', value: 3 },
            { text: '大于等于0', value: 4 },
            { text: '小于等于0', value: 5 }
          ]
        },
        {
          type: 'RANGE_DATE',
          dateType: 'daterange',
          label: '最近出入库',
          labelWidth: '120px',
          fieldName: 'DateBegin|DateEnd',
          valueFormat: 'yyyy-MM-dd',
          labelOptions: {
            fieldName: 'dateType',
            initialValue: 'finished',
            itemList: [
              { text: '最近出入库', value: 'finished' },
              { text: '最近入库', value: 'lastIn' },
              { text: '最近出库', value: 'lastOut' }
            ]
          }
        },
        // {
        //   type: 'RANGE_DATE',
        //   dateType: 'daterange',
        //   label: '最近入库',
        //   fieldName: 'lastInDateBegin|lastInDateEnd',
        //   valueFormat: 'yyyy-MM-dd'
        // },
        // {
        //   type: 'RANGE_DATE',
        //   dateType: 'daterange',
        //   label: '最近出库',
        //   fieldName: 'lastOutDateBegin|lastOutDateEnd',
        //   valueFormat: 'yyyy-MM-dd'
        // },
        {
          type: 'SELECT',
          label: '账面库存',
          fieldName: 'stockQuantity',
          itemList: [
            { text: '非0', value: 1 },
            { text: '等于0', value: 2 }
          ]
        },
        // ep-24249 添加最近出入库小于动态查询
        {
          type: 'DATE',
          dateType: 'date',
          label: '最近出入库',
          labelWidth: '130px',
          fieldName: 'Date1',
          valueFormat: 'yyyy-MM-dd',
          labelOptions: {
            fieldName: 'datType',
            label: '小于',
            initialValue: 'finished',
            itemList: [
              { text: '最近出入库小于', value: 'finished' },
              { text: '最近入库小于', value: 'lastIn' },
              { text: '最近出库小于', value: 'lastOut' }
            ]
          },
          change: val => this.dateChangeRule(val)
        },
        {
          type: 'SELECT',
          label: '账面库存排序',
          labelWidth: '100px',
          fieldName: 'InventorySort',
          itemList: [
            { text: '库存升序', value: 'up' },
            { text: '库存降序', value: 'down' }
          ]
        }
      ];
    },
    createPartColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: params => {
            return (
              <div>
                <el-button
                  type="text"
                  onClick={() => {
                    this.handleViewDetail(params.row);
                  }}
                >
                  查看
                </el-button>
                <el-button
                  type="text"
                  onClick={() => {
                    this.handleCheckReplacePart(params.row);
                  }}
                >
                  替换
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '配件分类代码',
          dataIndex: 'PART_SORT_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8106'),
          dictItems: this.createDictList('8106'),
          // render: params => {
          //   return <span>{this.createDictText(params.row.PART_SORT_CODE, '8106')}</span>;
          // },
          showOverflowTooltip: true
        },
        {
          title: '配件类别',
          dataIndex: 'PART_GROUP_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8075'),
          dictItems: this.createDictList('8075'),
          render: props => {
            return <span>{this.createDictText(props.row.PART_GROUP_CODE, '8075')}</span>;
          },
          showOverflowTooltip: true
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          summationDataIndex: 'partCount',
          summationUnit: '品种合计',
          showOverflowTooltip: true
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          summationDataIndex: 'cgcb',
          summationUnit: '库存采购成本',
          showOverflowTooltip: true
        },
        {
          title: '配件说明',
          dataIndex: 'PART_DESCRIPTION',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          summation: true,
          summationDataIndex: 'cgcb',
          summationUnit: '库存采购成本',
          showOverflowTooltip: true
        },
        {
          title: '配件车型组集',
          dataIndex: 'PART_MODEL_GROUP_CODE_SET',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          precision: 2,
          filter: true,
          filterType: 'number',
          summation: true,
          summationDataIndex: 'kcsl',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '可用库存',
          dataIndex: 'USERBLE_QUANTITY',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          summation: true,
          summationDataIndex: 'userbleQuantity',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '欠料数量',
          dataIndex: 'OWE_NUMBER',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          summation: true,
          summationDataIndex: 'oweNumber',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        // {
        //   title: '借进数量',
        //   dataIndex: 'BORROW_QUANTITY',
        //   sorter: true,
        //   precision: 2,
        //   numberFormat: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        // {
        //   title: '借出数量',
        //   dataIndex: 'LEND_QUANTITY',
        //   sorter: true,
        //   precision: 2,
        //   numberFormat: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        // {
        //   title: '索赔价',
        //   dataIndex: 'CLAIM_PRICE',
        //   sorter: true,
        //   precision: 2,
        //   numberFormat: true
        // },
        {
          title: '预留量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          summation: true,
          summationDataIndex: 'lockedQuantity',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '含税销售价',
          dataIndex: 'COST_SALES_PRICE',
          // dataIndex: 'SALES_PRICE',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '含税批发单价',
          dataIndex: 'COST_WHOLESALES_PRICE',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '建议含税销售价',
          dataIndex: 'REFER_PRICE',
          // dataIndex: 'INSTRUCT_PRICE',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          render: props => {
            return <span>{Number(props.row.REFER_PRICE * (1 + Number(this.tax))).toFixed(2)}</span>;
          },
          exportFormat: {
            t: 'n'
          }
        },
        // {
        //   title: '终端建议零售价格',
        //   dataIndex: 'INSURANCE_PRICE',
        //   sorter: true,
        //   precision: 2,
        //   numberFormat: true
        // },
        {
          title: '销售限价',
          dataIndex: 'LIMIT_PRICE',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '急件价格',
          dataIndex: 'URGENT_PRICE',
          sorter: true,
          precision: 2,
          numberFormat: true,
          filter: true,
          filterType: 'number',
          exportFormat: {
            t: 'n'
          }
        },

        {
          title: '不含税成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          exportFormat: {
            t: 'n'
          }
        },

        {
          title: '含税成本单价',
          dataIndex: 'NET_PRICE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '不含税成本金额',
          dataIndex: 'COST_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'costAmount',
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '含税成本金额',
          dataIndex: 'NET_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'taxCostAmount',
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '九大类',
          dataIndex: 'PART_MAIN_TYPE',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.PART_MAIN_TYPE, '8094')}</span>;
          },
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8094'),
          dictItems: this.createDictList('8094'),
          showOverflowTooltip: true
        },
        {
          title: '计量单位名称',
          dataIndex: 'UNIT_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '借进数量',
          dataIndex: 'BORROW_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'borrowQuantity',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '借出数量',
          dataIndex: 'LEND_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'lendQuantity',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        // {
        //   title: '产地',
        //   dataIndex: 'PRODUCTING_AREA',
        //   sorter: true
        // },
        {
          title: '储备高限',
          dataIndex: 'MAX_STOCK',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '储备底限',
          dataIndex: 'MIN_STOCK',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '最小包装数',
          dataIndex: 'PACKAGE_LIAGHT',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '最新入库日期',
          dataIndex: 'LAST_STOCK_IN',
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '最新出库日期',
          dataIndex: 'LAST_STOCK_OUT',
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '不含税期初金额',
          dataIndex: 'OPEN_AMOUNT',
          precision: 2,
          sorter: true,
          filter: true,
          filterType: 'number',
          summation: true,
          summationDataIndex: 'openAmount',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '本期不含税入库成本金额',
          dataIndex: 'STOCK_IN_AMOUNT',
          precision: 2,
          summation: true,
          summationDataIndex: 'stockInAmount',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '本期不含税出库成本金额',
          dataIndex: 'OUT_AMOUNT',
          precision: 2,
          summation: true,
          summationDataIndex: 'outAmount',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '本期不含税盈亏成本金额',
          dataIndex: 'CLOSE_AMOUNT',
          precision: 2,
          summationDataIndex: 'closeAmount',
          summation: true,
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'n'
          }
        },
        {
          title: '库龄日',
          dataIndex: 'STOCK_AGE_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '库龄',
          dataIndex: 'STOCK_AGE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '建档日期',
          dataIndex: 'FOUND_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '是否停用',
          dataIndex: 'PART_STATUS',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.PART_STATUS, '1004')}</span>;
          },
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '订货周期',
          dataIndex: 'LEAD_TIME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '拼音代码',
          dataIndex: 'SPELL_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '常用件标识',
          dataIndex: 'IS_COMMON_PART',
          sorter: true,
          render: params => {
            return <span>{params.row.IS_COMMON_PART == 10041001 ? '是' : '否'}</span>;
          },
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '替代配件',
          dataIndex: 'OPTION_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '加价率',
          dataIndex: 'PRICE_ADD_RATE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    createBottomColumns() {
      return [
        {
          title: '一月',
          dataIndex: 'outQuantity1'
        },
        {
          title: '二月',
          dataIndex: 'outQuantity2'
        },
        {
          title: '三月',
          dataIndex: 'outQuantity3'
        },
        {
          title: '四月',
          dataIndex: 'outQuantity4'
        },
        {
          title: '五月',
          dataIndex: 'outQuantity5'
        },
        {
          title: '六月',
          dataIndex: 'outQuantity6'
        },
        {
          title: '七月',
          dataIndex: 'outQuantity7'
        },
        {
          title: '八月',
          dataIndex: 'outQuantity8'
        },
        {
          title: '九月',
          dataIndex: 'outQuantity9'
        },
        {
          title: '十月',
          dataIndex: 'outQuantity10'
        },
        {
          title: '十一月',
          dataIndex: 'outQuantity11'
        },
        {
          title: '十二月',
          dataIndex: 'outQuantity12'
        }
      ];
    },
    createBottomColumns2() {
      return [
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '批号',
        //   dataIndex: 'PART_BATCH_NO',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '期初数量',
          dataIndex: 'OPEN_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '入库数量',
          dataIndex: 'IN_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出库数量',
          dataIndex: 'OUT_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '尚欠数量',
          dataIndex: 'AMOUNT_OWED',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借出数量',
          dataIndex: 'ALLOCATE_OUT_COUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '锁定数量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '欠料锁定数量',
          dataIndex: 'BACKLOG_LOCKED_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开单数量',
          dataIndex: 'SALE_OUT_COUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发布中数量',
          dataIndex: 'NUMBER_OF_RELEASES',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '盘点数量',
          dataIndex: 'INVENTORY_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借入数量',
          dataIndex: 'ALLOCATE_IN_COUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '账面库存',
          dataIndex: 'BOOK_INVENTORY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实物库存',
          dataIndex: 'PHYSICAL_INVENTORY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '不含税期初金额',
          dataIndex: 'OPEN_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '本期不含税入库成本金额',
          dataIndex: 'STOCK_IN_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '本期不含税出库成本金额',
          dataIndex: 'STOCK_OUT_COST_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '本期不含税盈亏成本金额',
          dataIndex: 'P_L_COST_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      this.fetchParams.xhrAbort = true;

      this.fetchParams = Object.assign(this.fetchParams, val, {
        xhrAbort: false,
        ptype: this.ptype ? this.ptype : null,
        [`${val.dateType}DateBegin`]: val.DateBegin,
        [`${val.dateType}DateEnd`]: val.DateEnd
      });
    },
    dateChangeRule(val) {
      if (val) {
        this.partInfoFilterList.find(x => x.fieldName === 'ageBegin|ageEnd').initialValue = null;
        this.partInfoFilterList.find(x => x.fieldName === 'ageBegin|ageEnd').disabled = true;
      } else {
        this.partInfoFilterList.find(x => x.fieldName === 'ageBegin|ageEnd').disabled = false;
      }
    },
    // 点击查看按钮
    handleViewDetail(e) {
      this.checkDetailRowInfo = e;
      this.detailVisible = true;
    },
    // 配件单击或者双击
    handlePartEnterEvent(e) {
      console.log(e);
      this.queryInfoPart = e || this.queryInfoPart;
      // 查询库存数量信息
      this.bottomFetchParams2.xhrAbort = true;
      this.bottomFetchParams2 = Object.assign(this.bottomFetchParams2, {
        partNo: this.queryInfoPart.PART_NO,
        storageCode: this.queryInfoPart.STORAGE_CODE,
        xhrAbort: false
      });
      // 查询年化信息
      this.bottomFetchParams.xhrAbort = true;
      let yearInfo = this.queryYearInfo();
      this.bottomFetchParams = Object.assign(this.bottomFetchParams, {
        xhrAbort: false,
        reportYear: this.yearFilterType == 1 ? yearInfo.thisYear : yearInfo.lastYear,
        partNo: this.queryInfoPart.PART_NO
      });
    },
    // 返回当前年份跟上年年份
    queryYearInfo() {
      let date = new Date();
      return {
        thisYear: date.getFullYear(),
        lastYear: date.getFullYear() - 1
      };
    },
    // 点击选中table行项
    handleTableRowSelect(e) {
      if (e.length) {
        this.handlePartEnterEvent(e[0]);
      }
    },
    // 点击查看替代件
    handleCheckReplacePart(row) {
      row.partNo = row.PART_NO;
      this.visibleReplacePartInfo = row;
      this.replacePartVisible = true;
    },
    // 打印配件动态盘点清单
    async handlePrint() {
      // 校验仓库、时间区间段必填
      let searchParams = await this.$refs.topFilter.GET_FORM_DATA();
      let { storageCode, dateType, DateBegin, DateEnd } = searchParams[1];

      if (!storageCode) return this.$notify.warning({ title: '提示信息', message: '打印配件动态盘点清单必须选择仓库' });
      if (!DateBegin || !DateEnd) return this.$notify.warning({ title: '提示信息', message: '打印配件动态盘点清单必须选择时间区段' });
      // 查询打印数据
      this.printBtnLoading = true;
      let dataList = [];
      try {
        let dateListRes = await queryPartInventoryPrintData(
          Object.assign({}, searchParams[1], {
            [`${dateType}DateBegin`]: DateBegin,
            [`${dateType}DateEnd`]: DateEnd
          })
        );
        if (dateListRes.resultCode == 200) {
          dataList = dateListRes.data;
        }
      } catch (err) {
        console.log('获取配件动态盘点清单数据失败', err);
      } finally {
        this.printBtnLoading = false;
      }
      // 翻译仓库及时间类型
      let storageName = this.partInfoFilterList.find(item => item.fieldName == 'storageCode').itemList.find(item => item.value == storageCode).text;
      let timeTypeName = this.partInfoFilterList.find(item => item.fieldName == 'DateBegin|DateEnd').labelOptions.itemList.find(item => item.value == dateType).text;
      this.printData = {
        storage: storageName,
        timeType: timeTypeName,
        beginDate: DateBegin.split(' ')[0],
        endData: DateEnd.split(' ')[0],
        dataList
      };
      this.$refs.print.EXCUTE_PRINT();
    },
    // 查询打印参数
    async queryPrintParams() {
      let res = await dealerPrintApi({
        vModule: '90211009',
        vNormalCode: 'BJDT'
      });
      if (res.resultCode == 200 && res.data.length) {
        this.printParams = res.data[0];
      }
      console.log(this.printParams, '打印参数');
    },
    // table数据改变
    handleTableDataChange(list) {
      list && list.forEach(item => (item.PART_SORT_CODE = item.PART_SORT_CODE ? +item.PART_SORT_CODE : ''));
    }
  }
};
</script>

<style scoped>
.bottomInfoWrap {
  display: flex;
}
.bottomInfoWrap > div {
  width: 50%;
}
</style>
